package com.ly.honor.controller;



import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ly.honor.entity.dto.*;
import com.ly.honor.entity.vo.HonorCountVO;
import com.ly.honor.entity.vo.HonorQueryVO;
import com.ly.honor.entity.vo.PlayerHonorQueryVO;
import com.ly.honor.service.HonorService;
import com.ly.honor.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;
import java.util.Map;

/**
 * (Honor)表控制层
 *
 * @author makejava
 * @since 2022-11-16 11:53:59
 */
@RestController
@RequestMapping("honor")
@Api(tags = "荣誉管理")
public class HonorController {
    /**
     * 服务对象
     */
    @Resource
    private HonorService honorService;



    /**
     * 条件分页查询
     * @param pageNum
     * @param pageSize
     * @param honorQueryDTO
     * @return
     */
    @ApiOperation("条件分页查询")
    @PostMapping("selectHonorPage/{pageNum}/{pageSize}")
    public Result selectHonorPage(@PathVariable("pageNum") long pageNum,
                                  @PathVariable("pageSize") long pageSize,
                                  @RequestBody(required = false) HonorQueryDTO honorQueryDTO) {
        Page<HonorQueryVO> honorQueryVOPage  = honorService.selectHonorPage(pageNum,pageSize,honorQueryDTO);
        return Result.ok(honorQueryVOPage);
    }

    @ApiOperation("分页选手荣誉")
    @PostMapping("getPlayerHonorPage/{pageNum}/{pageSize}")
    public Result getPlayerHonorPage(@PathVariable("pageNum") long pageNum,
                                     @PathVariable("pageSize") long pageSize,
                                        @RequestBody PlayerHonorQueryDTO playerDTO) {
        Page<PlayerHonorQueryVO> playerHonorQueryVOPage = honorService.getPlayerHonorPage(pageNum,pageSize,playerDTO);
        return Result.ok(playerHonorQueryVOPage);
    }

    @ApiOperation("查看所有选手荣誉")
    @PostMapping("getPlayerHonorAll")
    public Result getPlayerHonorAll() {
        List<PlayerHonorQueryVO> playerHonorQueryVOList = honorService.getPlayerHonorAll();
        return Result.ok(playerHonorQueryVOList);
    }

    @ApiOperation("荣誉统计")
    @GetMapping("findHonorCount")
    public Result findHonorCount(){
        Map<String,Object> map = honorService.findHonorCount();
        return Result.ok(map);
    }

    @ApiOperation("查询所有数据")
    @GetMapping("getPlayerHonorList")
    public Result getPlayerHonorList() {
        return Result.ok(honorService.list());
    }

    @ApiOperation("根据人查看荣誉")
    @PostMapping("getHonorByPlayer")
    public Result getHonorByPlayer( Integer playerId) {
        List<Integer> honorIdList = honorService.getHonorByPlayer(playerId);
        return Result.ok(honorIdList);
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @ApiOperation("通过主键查询单条数据")
    @GetMapping("getHonorById/{id}")
    public Result getHonorById(@PathVariable long id) {
        HonorQueryVO honorQueryVO = honorService.getHonorById(id);
        return Result.ok(honorQueryVO);
    }

    /**
     * 新增数据
     *
     * @param honorCreateDTO 实体对象
     * @return 新增结果
     */
    @PostMapping("insertHonor")
    @ApiOperation("新增荣誉")
    public Result insertHonor(@RequestBody @Valid HonorCreateDTO honorCreateDTO) {
        honorService.insertHonor(honorCreateDTO);
        return Result.ok();
    }

    @PostMapping("insertPlayerHonor")
    @ApiOperation("新增选手荣誉")
    public Result insertPlayerHonor(@RequestBody @Valid PlayerHonorCreateDTO playerHonorCreateDTO) {
        honorService.insertPlayerHonor(playerHonorCreateDTO);
        return Result.ok();
    }

    /**
     * 修改数据
     *
     * @param honorEditDTO 实体对象
     * @return 修改结果
     */
    @PostMapping("updateHonor")
    @ApiOperation("修改荣誉")
    public Result updateHonor(@RequestBody @Valid HonorEditDTO honorEditDTO) {
        honorService.updateHonor(honorEditDTO);
        return Result.ok();
    }

    /**
     * 修改数据
     *
     * @param playerHonorEditDTO 实体对象
     * @return 修改结果
     */
    @PostMapping("updatePlayerHonor")
    @ApiOperation("修改选手荣誉")
    public Result updatePlayerHonor(@RequestBody PlayerHonorEditDTO playerHonorEditDTO) {
        honorService.updatePlayerHonor(playerHonorEditDTO);
        return Result.ok();
    }

    @ApiOperation("通过id删除数据")
    @DeleteMapping("deleteHonorById/{id}")
    public Result deleteHonorById(@PathVariable long id){
        honorService.deleteHonorById(id);
        return Result.ok();
    }

    /**
     * 删除数据
     *
     * @param idList 主键结合
     * @return 删除结果
     */
    @ApiOperation("批量删除")
    @DeleteMapping("removeBatch")
    public Result removeBatch(@RequestBody List<Long> idList) {
        honorService.removeBatch(idList);
        return Result.ok();
    }

    @ApiOperation("战队荣誉分布")
    @GetMapping("getClueHonor")
    public Result getClueHonor(){
        List<JSONObject> clueHonorList = honorService.getClueHonor();
        return Result.ok(clueHonorList);
    }


}

